$(function(){
	unbundledCard();
});

function unbundledCard(){
	$('#button').unbind('click');
	$('#button').bind('click',function(){
		var phoneReg = /^(13[0-9]|14[57]|15[0-35-9]|17[0135678]|18[0-9])[0-9]{8}$/;
		var platformCuIdReg = /^[0-9]+$/;
		var merKeyReg = /^[A-Za-z0-9]+$/;
		var certIdReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
		var phone = $('#phone').val();
		var platformCuId = $('#platformCuId').val();
		var creditCard = $('#creditCard').val();
		var userName = $('#userName').val();
		var certId = $('#certId').val();
		var merKey = $('#merKey').val();
		
		if(!platformCuIdReg.test(platformCuId)){
			alertMsg('请输入正确的商户号码!');
			return;
		}
		if(!phoneReg.test(phone)){
			alertMsg('请输入正确的手机号码!');
			return;
		}
		
		if(!platformCuIdReg.test(creditCard)){
			alertMsg('请输入正确的卡号!');
		}
		
		if($.trim(userName) == ''){
			alertMsg('真实姓名不能为空!');
			return;
		}
		if(!certIdReg.test(certId)){
			alertMsg('请输入正确的身份证号!');
			return;
		}
		
		if(!merKeyReg.test(merKey)){
			alertMsg('请输入正确的merKey!');
			return;
		}
		
		var params = {
				 phone:phone,
				 platformCuId:platformCuId,
				 creditCard:creditCard,
				 userName:userName,
				 certId:certId,
				 merKey:merKey
		};
		
		var reqUrl = '../unbundled/unbundledCard';
		$.ajax({
			url: reqUrl,
			type: 'POST',
			//同步执行
			async:false,
			data: params,
			dataType: 'json',
			success: function(data) {
				var result = data.result;
				var result = eval('('+ result +')');
				if(result != undefined){
					$('#result').text(JSON.stringify(data));
				}else{
					alertMsg("未知错误");
				}
			},
			error: function(data) {
				alertMsg("未知错误");
			}
		 });
	});
}

function alertMsg(msg){
	var params = {
	    container : {
		    content :msg
		  },
		autoClose : 1500
	};
	easyDialog.open(params);
}